package com.runvp.config;

import com.runvp.common.core.domain.AjaxResult;
import com.runvp.netty.constant.NettyConstant;
import com.runvp.task.NettyServerTask;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

@Slf4j
@Controller
@ResponseBody
@RequestMapping("/app/config")
public class ConfigController {

    @Autowired
    private NettyServerTask nettyServerTask;

    /**
     *  配置刷新
     */
    @GetMapping("/plat/channels")
    public AjaxResult channels(String key) {
        //刷新通道
        if(StringUtils.isNotBlank(key) && "clear".equals(key)){
            nettyServerTask.exeRefreshChannel();
        }
        Map<String,Object> map = new LinkedHashMap<>();
        map.put("channelsName",NettyConstant.channels.name());
        map.put("channelCount",NettyConstant.channels.size());
        map.put("normalChannels",NettyConstant.getNormals());
        map.put("allOnlineChannelIds",NettyConstant.allOnlineChannleIds);
        map.put("all",NettyConstant.all);
        map.put("channelIdMap",NettyConstant.channelIdMap);
        return AjaxResult.success(map);
    }


}
